package com.zhiletu.collect.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 *
 * @Title: DateUtil.java
 * @Package com.zhiletu.collect.util
 * @Description: 日期操作工具栏
 * @author zhiletu.com
 * @date 2021年3月11日
 * @version V1.0
 */
public class DateUtil {
	public static String getDateTimeStamp(int count) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(new Date(System.currentTimeMillis() + 1000 * count));
	}

//	public static void main(String[] args){
//		String str = DateUtil.getDateTimeStamp(5);
//		System.out.println(str);
//	}

	/**
	 * 整点设置
	 * @param hour
	 * @return
	 */
	public static int getTimesmorning(int hour) {
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.HOUR_OF_DAY, hour);
		cal.set(Calendar.SECOND, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.MILLISECOND, 0);
		return (int) (cal.getTimeInMillis() / 1000);
	}

	/**
	 * 返回离设置时间还有多少秒
	 * @param hour
	 * @return
	 */
	public static int getTimeToSet(int hour) {
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.HOUR_OF_DAY, hour);
		cal.set(Calendar.SECOND, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.MILLISECOND, 0);
		int exec = (int) (cal.getTimeInMillis() / 1000);
		long time = new Date().getTime();
		int cur = (int) (time / 1000);

		return Math.abs(cur - exec);
	}
}
